package com.gof.example.iterator;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Created by zhiyuan on 2018/5/10 22:59.
 * haiming.fei@tongdun.cn
 */
public class PageIterator extends Iteratable {

    private List list;
    private int currentIndex;

    public PageIterator(PageList pageList) {
        this.list = pageList.getList();
        currentIndex = 0;
    }

    @Override
    public Object next() {
        if (currentIndex < list.size()) {
            return list.get(currentIndex++);
        }

        return null;
    }

    @Override
    public boolean hasNext() {
        return currentIndex < list.size();
    }

    @Override
    public int currentIndex() {
        return currentIndex;
    }
}
